﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ExportXLS : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    Response.Clear();
    HiddenField hd = (HiddenField)PreviousPage.FindControl("xls");
    string htmltable = hd.Value;
    System.Text.StringBuilder sb = new System.Text.StringBuilder(Server.UrlDecode(htmltable));
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter(sb);
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
    //this.RenderControl(oHtmlTextWriter);
    Response.Write(@"<html>
<style>
table tr td {
border: 1px solid #000000;
border-collapse:collapse;
}
</style>
        <body>");
    Response.Write(oStringWriter.ToString());
    Response.Write("</body></html>");
    Response.AddHeader("Content-type", "application/application/ms-excel");
    Response.AddHeader("content-disposition", "attachment; filename=\"data.xls\"");
    //Response.End();

  }
}
